/*
* Copyright (c) 2024 China Unicom Digital Technology Co., Ltd.
* openFuyao is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*          http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: YuXiang Guo
* Date: 2024-11-25
 */

package cpuset

import (
	"testing"

	"k8s.io/utils/pointer"

	"openfuyao.com/colocation-management/pkg/colocation-overquota-agent/nriserver/core"
	"openfuyao.com/colocation-management/pkg/common"
	"openfuyao.com/colocation-management/pkg/utils"
)

// TestSetContainerCPUSet
func TestSetContainerCPUSet(t *testing.T) {

	info := core.ContainerInfo{
		ContainerRequest: core.ContainerRequest{
			PodSandboxConfig: utils.PodSandboxConfig{
				Annotations: map[string]string{
					common.QosClassAnnotationKey: "BE",
				},
			},
		},
	}
	err := NewCpuSetRunner().SetContainerCPUSet(&info)
	if err != nil {
		t.Fatal(err)
	}
}

// TestUnsetPodCPUQuota
func TestUnsetPodCPUQuota(t *testing.T) {

	info := core.PodInfo{
		PodResponese: core.PodResponse{
			Resources: utils.LinuxContainerResources{
				CPUShares:   pointer.Int64(2048),
				CFSQuota:    pointer.Int64(200000),
				MemoryLimit: pointer.Int64(2147483648),
			},
		},
	}
	err := NewCpuSetRunner().UnsetPodCPUQuota(&info)
	if err != nil {
		t.Fatal(err)
	}
}

// TestGetcontainerCPUSet
func TestGetcontainerCPUSet(t *testing.T) {

	info := core.ContainerInfo{
		ContainerRequest: core.ContainerRequest{
			PodSandboxConfig: utils.PodSandboxConfig{
				Annotations: map[string]string{
					common.QosClassAnnotationKey: "BE",
				},
			},
		},
	}
	_, err := getContainerCPUSet(&info.ContainerRequest)
	if err != nil {
		t.Fatal(err)
	}
}
